var jwt =require('jsonwebtoken');
var jwtSecret='haha'; //签名
module.exports={
    setToken:(username,userid)=>{
        return new Promise((resolve,reject)=>{
            const token=jwt.sign({username:username,userid:userid},jwtSecret,{expiresIn:60*60}); //时效
            resolve(token);
        });
    },
    getToken:(token)=>{ 
        //将客户端的token传过来
        return new Promise((resolve,reject)=>{
            if(token){
                const info=jwt.verify(token.split(' ')[1],jwtSecret); //通过验证后返回一个info信息,然后通过空格来分切签名
                resolve(info);
            }else{
                reject({error:'token为空'})
            }
            
        })

    }
}